

let fs = require("fs")

let units = require("./unitdatas.js")

units = units.map(v=>formatData(v))

units.sort((b,a) => {
    let ar = getPoint(a)
    let br = getPoint(b)
    return ar.v1-br.v1 || ar.v2-br.v2 || ar.v3-br.v3
});

console.log(units[4]);

function getPoint(data) {
    let ret = {
        v1:0, v2:0, v3:0
    }
    if(data.prop.includes("妙算")){  // 扫荡 坚守 疾走 地利 使役 山战 林战 长驱 屯田 威风 妙算 机智 
        ret.v1 = 10000
    }
    

    ret.v2 = data.skill.tong + data.skill.wu + data.skill.zhi 

    return ret
}


function formatData(data) {
    let ret = {
        id: data[0],
        sex: data[1],
        skill: {
            tong: data[2],
            wu: data[3],
            zhi: data[4],
            zhen: data[5],
            mei: data[6],
        },
        mainType: data[7],
        mainCat: data[8],
        catValue: data[9],
        object: data[10],
        name: data[11],
        prop: []
    }
    for (let index = 12; index < data.length; index++) {
        ret.prop.push(data[index])
    }
    return ret
}